package test2

/**
  * Created by Bane.Shi.
  * Copyright MoenSun
  * User: Bane.Shi
  * Date: 2017/7/27
  * Time: 22:56
  */
object Test3 {

  def findFirst[A](as:Array[A],p:A=>Boolean): Int = {
    def loop(n:Int):Int =
      if(n>as.length) -1
      else if (p(as(n))) n
      else loop(n+1)

    loop(0)
  }

  def main(args: Array[String]): Unit = {
    val s = findFirst(Array(7,9,13),(x:Int)=>x==9)
    println(s)
  }

}
